package hr.fer.ztel.rassus.brbljaonica.gui;

import hr.fer.ztel.rassus.brbljaonica.business.BusinessProvider;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * Klasa koja predstavlja glavni prozor
 */
public class MainWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public MainWindow() {
		setSize(new Dimension(500, 430));
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				BusinessProvider.disconnect();
				System.exit(0);
			}
		});
		getContentPane().setLayout(new GridLayout(1, 0, 0, 0));
		
		JPanel mainPanel = new JPanel();
		getContentPane().add(mainPanel);
		mainPanel.setLayout(new CardLayout(0, 0));
		
		LoginPanel loginPanel = new LoginPanel();
		mainPanel.add(loginPanel, "login");
		
		RegistrationFormPanel registrationFormPanel = new RegistrationFormPanel();
		mainPanel.add(registrationFormPanel, "registration");
		
		MainAppPanel mainAppPanel = new MainAppPanel();
		mainPanel.add(mainAppPanel, "main");
		
		setVisible(true);
	}
	
	public static void main(String[] args) {
		try {
			//XMPPConnection.DEBUG_ENABLED = true;
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}
		new MainWindow();
	}
}
